package com.book.controller.api;

import com.book.entity.Users;
import com.book.service.BookService;
import com.book.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author zzw2000
 * @Date 2022年08月28日 7:42
 * @Description 描述
 */
@Controller
@RequestMapping("/api/user")
public class UserApiController {

    @Resource
    private BookService bookService;
    @Resource
    private UserService userService;

    @GetMapping("/borrowBook")
    public String borrowBook(@SessionAttribute(value = "user", required = false) Users users,
                             @RequestParam("bid") int bid) {

        bookService.borrowBook(users.getId(), bid);
        return "redirect:/page/user/book";
    }

    @GetMapping("/returnBook")
    public String returnBook(@RequestParam("id") Integer id, @RequestParam("bid") Integer bid) {
        bookService.returnBook(id, bid);
        return "redirect:/page/user/book";
    }

    @PostMapping("/person")
    public String update(@RequestParam("sid") Integer sid,
                         @RequestParam("uid") Integer uid,
                         @RequestParam("sex") String sex,
                         @RequestParam("grade") Integer grade,
                         @RequestParam("password") String password) {
        userService.updateStu(sid, uid, sex, grade, password);
        return "redirect:/page/user/index";
    }
}
